package com.lanlian.cayman.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.example.utils.DrawStyleUtil;
import com.lanlian.cayman.R;
import com.lanlian.cayman.activity.KLineHengPingActivity;
import com.lanlian.cayman.activity.MainActivity;
import com.lanlian.cayman.activity.ZixuanActivity;
import com.lanlian.cayman.widget.StyleUtil;
import com.scwang.smartrefresh.layout.util.DensityUtil;

/**
 * <pre>
 *     date   : 2018/8/22 20:09
 *     desc   : 颜色选择对话框
 *     version: 1.0
 * </pre>
 */
public class ColorPopup  implements View.OnClickListener {
    /**
     * 当前选择的的颜色
     */
   public ColorView mcv;
    private KLineHengPingActivity mContext;
    StyleUtil su;
    PopupWindow window;

    private ColorView mCv1;
    private ColorView mCv2;
    private ColorView mCv3;
    private ColorView mCv4;
    private ColorView mCv5;
    private ColorView mCv6;
    private ColorView mCv7;
    private ColorView mCv8;
    private ColorView mCv9;
    private ColorView mCv10;
    private ColorView mCv11;
    private ColorView mCv12;
    private ColorView mCv13;
    private ColorView mCv14;
    private ColorView mCv15;



    public ColorPopup(Activity mContext,StyleUtil su)
   {
       this.mContext=(KLineHengPingActivity)mContext;
       this.su=su;
       initView();
   }
   public void showPopup(View view)
   {
       DensityUtil du=new DensityUtil();
       int width= du.dip2px(100);

       int height=du.dip2px(44+20);


       window.showAtLocation(view,Gravity.TOP|Gravity.RIGHT,width,height);
   }

    private void initView() {
        LinearLayout ll=new LinearLayout(mContext);
        // 用于PopupWindow的View
        View view= LayoutInflater.from(mContext).inflate(R.layout.dialog_colorselect, ll, false);
        DensityUtil du=new DensityUtil();
        int width= du.dip2px(350);
        int heiht= du.dip2px(230);
        window=new PopupWindow(view, width, heiht, true);
        // 设置PopupWindow是否能响应外部点击事件
        window.setOutsideTouchable(false);
        // 设置PopupWindow是否能响应点击事件
        window.setTouchable(true);


        mCv1 = view.findViewById(R.id.cv1);
        mCv2 = view.findViewById(R.id.cv2);
        mCv3 = view.findViewById(R.id.cv3);
        mCv4 = view.findViewById(R.id.cv4);
        mCv5 = view.findViewById(R.id.cv5);
        mCv6 = view.findViewById(R.id.cv6);
        mCv7 = view.findViewById(R.id.cv7);
        mCv8 = view.findViewById(R.id.cv8);
        mCv9 = view.findViewById(R.id.cv9);
        mCv10 = view.findViewById(R.id.cv10);
        mCv11 = view.findViewById(R.id.cv11);
        mCv12 = view.findViewById(R.id.cv12);
        mCv13 = view.findViewById(R.id.cv13);
        mCv14 = view.findViewById(R.id.cv14);
        mCv15 = view.findViewById(R.id.cv15);


        mCv1.setColor(0xff000000);
        mCv2.setColor(0xff1F51A4);
        mCv3.setColor(0xff461FA4);
        mCv4.setColor(0xffAC2020);
        mCv5.setColor(0xffE09C00);
        mCv6.setColor(0xff454E56);
        mCv7.setColor(0xff4385F3);
        mCv8.setColor(0xff7A43F3);
        mCv9.setColor(0xffE42E2E);
        mCv10.setColor(0xffEFBB00);
        mCv11.setColor(0xffB9BDC5);
        mCv12.setColor(0xffA1C3FC);
        mCv13.setColor(0xffB694FF);
        mCv14.setColor(0xffFF7C7C);
        mCv15.setColor(0xffFFE786);

        setListen(mCv1);
        setListen(mCv2);
        setListen(mCv3);
        setListen(mCv4);
        setListen(mCv5);
        setListen(mCv6);
        setListen(mCv7);
        setListen(mCv8);
        setListen(mCv9);
        setListen(mCv10);
        setListen(mCv11);
        setListen(mCv12);
        setListen(mCv13);
        setListen(mCv14);
        setListen(mCv15);


    }
    public void setListen(ColorView mCv)
    {
        if(mContext.kline.kLineView.styleView.getColor()==mCv.getColor())
        {
            mcv=mCv;
            mcv.setSelect(true);
        }
        mCv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 mcv.setSelect(false);
                 mcv=(ColorView) v;
                 mcv.setSelect(true);
                 mContext.kline.kLineView.styleView.setColor(mCv.getColor());
                 su.setColor(mCv.getColor());
                 mContext.kline.kLineView.invalidate();
             }
         });
    }


    @Override
    public void onClick(View v)
    {
        Intent intent=new Intent();
        int id = v.getId();
        switch (id)
        {
            case R.id.iv_close:

                break;
            default:
                break;

        }
    }












}
